<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>组织管理</title>
		<link href="<%=application.getContextPath()%>/nresources/ued/css/all-src.css" type="text/css" rel="stylesheet" />
		<%@include file="/WEB-INF/ibnms/common/easyui.jsp" %>
		<%@include file="/WEB-INF/ibnms/common/jqgrid.jsp"%>
</head>
<body>
<div class="form-wrapper">
    	<div class="form-title">
       		 <span class="ttcorner"></span>
             <h3>
                <span class="text">组织管理</span>
             </h3>
        </div>
        <form name="theForm" method="post">
			<input type="hidden" name="deptForm.SUPER_DEPT_ID" value="${deptForm.SUPER_DEPT_ID}"></input>
		</form>
        <div class="block02">
      		<div class="title-style02">
				<input class="btn-style02" type="button" id="btn-add" value="增加">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-edit" value="修改">&nbsp;&nbsp;
				<input class="btn-style02" type="button" id="btn-del" value="删除">
            </div>
            <table id="gridTable">
			</table>
			<div id="gridPager">
			</div>
       	</div>
</div>

</body>
<script type="text/javascript">
			$(function(){
				$(".title-style a.fold-tip").toggle(toggletip,toggletip);
				function toggletip() {
					if ($(this).attr("class").split("unfold-tip").length > 1) {
						$(this).removeClass("unfold-tip");
						$(this).parents().prev(".box-in").show("fast");
					} else {
						$(this).addClass("unfold-tip");
						$(this).parents().prev(".box-in").hide("fast");
					}
				}
				$('#sel1').click(function(){
										  var height = $(window.parent.document.getElementById('sideframe')).height();
						$(window.parent.document.getElementById('sideframe')).css("display","none").next(".sideframe-collapse").css({"display":"block","height":height});
				})
			})
			
			$(function(){$("#gridTable").jqGrid({
					url: "loadDeptListQueryJson.do",
					datatype: "json",
					mtype: "POST",
					height: "100%",
					autowidth: true,
					colNames:['ID', '部门名称', '部门管理员', '说明'],
					colModel:[
						{name:'DEPT_ID',index:'DEPT_ID',hidden:true},
						{name:'DEPT_NAME',index:'DEPT_NAME'},
						{name:'MGR_ID',index:'MGR_ID'},
						{name:'DEPT_DESC',index:'DEPT_DESC'}
					],
					viewrecords: true,
					rowNum: 15,
					rowList: [10,15,30],
					jsonReader: {
						root: 'rows',
						page: 'page',
						total: 'total',
						records: 'records',
						repeatitems: false,
						subgrid: {
					        root: 'rows',
							page: 'page',
							total: 'total',
							records: 'records',
							repeatitems: false
					    }      
					},
					pager: "#gridPager",
					hidegrid: true,
					multiselect: true,
					beforeRequest:function(){
						var postData = {};
						$(":input[name^='deptForm.']").each(function(){
							postData[$(this).attr("name")] = $(this).val();
						});
						$.extend($("#gridTable").getGridParam("postData"), postData);
					}
				});
				
			}); 
			
			
			$("#btn-search").click(function(){
				$("#gridTable").trigger("reloadGrid",[{page:1}]);
			});
			
			$("#btn-add").click(function(){
				$("form[name='theForm']").append("<input type='hidden' name='deptForm.ISMP_JSP_COMMAND' value='add'/>");
				$("form[name='theForm']").attr("action","<s:url action='editDepart' namespace='/'/>").submit();
			});
			$("#btn-del").click(function(){
			 	var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
                if (idArr.length == 0) {
                    alert("请先选择要删除的记录!");
                    return;
                }else if(idArr.length>1){
                	alert("一次只能删除一条记录!");
                	return;
                }
				if(confirm("是否删除所选的记录?")){
                    var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
					var DEPT_ID = data.DEPT_ID;

					$.ajax({
						type: "POST",
						async: false,
						url: "<s:url action="delDepart" namespace='/'/>?deptForm.deptId="+DEPT_ID,
						success: function(data){
	                        if (data != "true"){
								alert("删除失败:"+data);
	                        }else{
	                       		$("#gridTable").trigger('reloadGrid');
	                       		alert("删除成功");
	                       		parent.refreshNode();
	                       	}
						},
						error:function(xhr){  
							show_error(xhr);
						}
					});	
                }
			});
			$("#btn-edit").click(function() {
				var idArr = jQuery("#gridTable").jqGrid('getGridParam','selarrrow');
				switch (idArr.length) {
					case 0:
						alert("请先选择要修改的记录!");
						break;
					case 1:
						var data = jQuery("#gridTable").jqGrid('getRowData',idArr[0]);
						var DEPT_ID = data.DEPT_ID;
						$("form[name='theForm']").append("<input type='hidden' name='deptForm.ISMP_JSP_COMMAND' value='modify'/>");
						$("form[name='theForm']").append("<input type='hidden' name='deptForm.deptId' value='"+DEPT_ID+"'/>");
						$("form[name='theForm']").attr("action","<s:url action='editDepart' namespace='/'/>");
						$("form[name='theForm']").submit();
						break;
					default:
						alert("一次只能修改一条记录!");
				}
			}); 
		</script>
</html>            
